package muview;

import java.util.Date;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;



/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class DialogDatabasePath extends Dialog{
	
    private Shell shell = null;
    private GridLayout gridLayout = null;
    private GridData gridData = null;
    private String path = "";
    private Label lab_databasepath;
    private Text txt_databasepath;
    private Button but_databasepath;
    private Button but_confirm;
    
	DialogDatabasePath(Shell parent) {
	    super(parent);
	  }
	
	public String open() {
		Shell parent = getParent();
		//display = parent.getDefault();
        shell = new Shell(parent,  SWT.TITLE | SWT.CLOSE | SWT.BORDER);
        shell.setText("資料庫路徑");
        shell.setBounds(200,200,450,65);
        gridLayout = new GridLayout();
        gridLayout.numColumns = 4;
        shell.setLayout(gridLayout);
        
        lab_databasepath = new Label(shell, SWT.None);
        lab_databasepath.setText("資料庫路徑 :");
        lab_databasepath.setLayoutData(gridData);
        
        GridData txt_databasepathGridData = new GridData();
        txt_databasepathGridData.widthHint = 265;
        txt_databasepath = new Text(shell, SWT.BORDER);
        txt_databasepath.setLayoutData(txt_databasepathGridData);
        
        
        but_databasepath = new Button(shell, SWT.PUSH);
        but_databasepath.setText("選擇");
        but_databasepath.setLayoutData(gridData);
        but_databasepath.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent e) {
            	FileDialog fileDialog = new FileDialog(shell, SWT.OPEN);
            	fileDialog.setText("資料庫路徑");
            	fileDialog.setFilterPath("C:/");
                String[] filterExt = { "*.mdb" };
                fileDialog.setFilterExtensions(filterExt);
                String selected = fileDialog.open();
                if(selected!= null)
                	txt_databasepath.setText(selected);
            }
        });
        
        but_confirm = new Button(shell, SWT.PUSH);
        but_confirm.setText("確定");
        but_confirm.setLayoutData(gridData);
        but_confirm.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent e) {
            	path = txt_databasepath.getText();
            	shell.close();
            }
        });

        gridData = new GridData(GridData.FILL_HORIZONTAL);
        shell.open();
	    Display display = parent.getDisplay();
	    while (!shell.isDisposed()) {
	      if (!display.readAndDispatch())
	    	  display.sleep();
	    }
	    
	    return path;
	  }
}
